#pragma once
#include <stdint.h>
#include "Part.h"
#include "Scene/Path.h"
#include "Common/SceneDefine.h"
#include "Common/CharacterDefine.h"
#include "ProtoBuffer/AllProtocol.h"
//#include "AllProtocol.h"

struct TransSceneTmpInfo
{
	TransSceneTmpInfo()
	{
		dstSceneId = 0;
		dstmapId = 0;
	}
	uint32_t dstSceneId;
	uint32_t dstmapId;
	Point3<float> dstPos;
};

enum enMovingFlag
{
	enMovingFlag_None =0,
	enMovingFlag_Mouse =1,   //鼠标移动
	enMovingFlag_Rock	=2,  //摇杆移动
};

enum TimeId
{
	TIME_NONE = 0,
	TIMEID_MOVING,			//�ƶ�
	TIMEID_ROCKER_MOVING,	//ҡ���ƶ�
	TIMEID_CHEAT_MOVE,		//移动防作弊检测定时器
};

#define INTERVAL_MOVE_TIME 200
#define INTERVAL_MOVE_CHEAT_TIME 5000 //防作弊检测时间

class MovePart : public Part
{
protected:
	Path m_curMovePath;				//路径
	uint64_t m_StepStarttamp;		//上次走路的时间戳
	uint32_t m_curleftStep;     //当前剩余的步数
	enMovingFlag m_enMovingFlag;    //0表示没的移动，1表示鼠标移动，2表示摇杆移动
	float m_fRockAngle;				//摇杆改变角度
	ActorRockerMove_Type m_fRockType;			//摇杆类型
	uint32_t m_moveIntervalTime;    //服务器更新位置的间隔时间
	//float m_lastSpeed;			//保存玩家改变前的速度，比如技能变速，组队传送变速前保存，完了，记得还原
	uint64_t m_lastMoveTime;  //正常滑竿移动时间
	uint64_t m_lastRockRollTime;	//上次翻滚时间
	uint32_t m_moveErrorNum;		//违规行走次数，超过指定次数，T人
	bool m_isTeamFollow;			//是否是组队跟随状态
	float m_moveSpeed;				//移动速度，在组队情况下是队长速度
public:
	bool TransToInScene(Point3<float>& dstPos);         //同场景内传送
	bool TransSceneInLogic(Scene *pdstScene, Point3<float> transPos, STransParam &transParam);

	void SkillReadyToMove(float skillSpeed);			//技能触发的移动
	//void BeenSeeMoving(void *pContext, int32_t nLen);	//被其他玩家看见
	bool IsCanMove(Point3<float> &msgCurPos,float fSpeed =0,float interverTimeSec=0);			//校验玩家当前坐标
	bool JudgeMove(Point3<float> &msgCurPos, float fSpeed = 0, float interverTimeSec = 0);  //判断移动合法性
	void ReadyToMove();									//准备移动
	bool GetDstInfoFromC(uint32_t typeId, uint32_t instanceId, Point3<float>& dstPos, TransSceneTmpInfo& transTmpInfo);


public:
	MovePart();
	virtual ~MovePart();
	bool Init(Creature *pMaster, uint32_t partType, CharacterDBInfo* pCharacterDB = nullptr);
	bool UnInit();
	bool OnMsgHandle(uint32_t cmd, const char* data, uint32_t len);
	void OnExecute(uint16_t nEventID, uint64_t nSrcID, uint8_t bySrcType, void *pContext, int32_t nLen);
	void OnTimer(uint32_t nTimerId);
	void ResetMoveInfo();
	//
	bool TransScene(uint32_t sceneId, Point3<float>& dstPos, uint32_t mapId,STransParam &transParam); //强制传送(场景内传送、切场景传送)
	bool MoveTo(Point3<float>& dstPos);					//移动
	void StopMove();									//停止当前移动,广播告诉其他人
	void StopSelfMove();								//停止移动
	//获取移动信息
	void GetMoveingState(ActorMove &actorMove, ActorRockerMove & rockmove);
	//瞬间移动
	bool Teleporting(Point3<float> dstPos);
	//瞬移当前方向，指定距离的某个点上,里面会找一个可以放的点。
	//distance 单位为m
	Point3<float>  TeleportCurrentDis(float distance);
	//被击退
	bool BeatBack(Point3<float> dstPos);
	//处理摇杠移动
	void RockerMoveDoing(int32_t interval);

	//客户端消息处理
	void C2Move(const char* data, uint32_t len);		//客户端移动
	void C2SkillMove(const char* data, uint32_t len);	//技能客户端移动
	void C2TransPlace(const char *data,uint32_t len);   //场景传送
	void C2RockerMove(const char* data,uint32_t len);	//玩家摇杠移动
	void C2UpdatePos(const char* data, uint32_t len);
	void C2UpdateTeamPos(const char* data, uint32_t len); //更新组队玩家位置
	void C2TransFinish(const char* data, uint32_t len);
	void C2TeamMove(const char* data, uint32_t len);    //组队移动
	void C2TeamRockMove(const char* data, uint32_t len); //组队摇杆移动
	void C2TeamTranScene(const char* data, uint32_t len);  //组队传送消息
	//逻辑服接收其他服务器消息
	void S2LsRspSceneId(const char *data,uint32_t len); //收到申请场景Id结果
	bool S2LsRspSceneId(CenterRspSceneId& rspSceneInfo);


	bool IsCanMoveSpeed(float sendSpeed);

	void SyncPosition(int32_t interval = 200 );
	virtual void Update(uint64_t tick){}

	bool IsMoving() const;

	//是否是翻滚状态
	bool IsRoll() const;

	bool C2MoveFun(const ActorMove & moveData,bool bBroad = false,bool teamMove=false);
	bool C2RockerMoveFun(const ActorRockerMove & rockMoveData, bool bBroad = false);

	enMovingFlag GetMoveFlag();

	//判断是否作弊
	bool IsJudgeCheatMove();
	//设置组队跟随状态
	void SetTeamFollowFlag(bool bFlag,float teamSpeed=0);
};
